package com.zhilianbao.leyaogo.view.dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.bql.materialprogressbar.MaterialProgressBar;
import com.bql.variousdialog.utils.CornerUtils;
import com.bql.variousdialog.widget.base.BaseDialog;
import com.zhilianbao.leyaogo.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 进度条对话框 <br>
 * Created by Cyarie on 2016/1/7.
 */
public class ProgressDialog extends BaseDialog<ProgressDialog> {

    //进度条类型 水平  竖直
    public enum STYLE {
        HORIZONTAL, VERTICAL
    }

    private STYLE mStyle = STYLE.VERTICAL;
    @BindView(R.id.loadingProgressBar)
    MaterialProgressBar mLoadingProgressBar;
    @BindView(R.id.loadingText)
    TextView mLoadingText;
    private TextView mLoadingTv;

    private String text;

    private boolean applySkin;//是否运用皮肤属性

    public ProgressDialog(Context context) {
        super(context);
    }

    public ProgressDialog(Context context, boolean applySkin) {
        super(context);
        this.applySkin = applySkin;
    }

    public ProgressDialog(Context context, STYLE style) {
        super(context);
        mStyle = style;
    }


    @Override
    public View onCreateView() {
        widthScale(0);
        View view = null;
        if (mStyle == STYLE.VERTICAL) {
            view = View.inflate(mContext, R.layout.dialog_progress_vertical, null);
        } else {
            view = View.inflate(mContext, R.layout.dialog_progress_horizontal, null);
        }
        if (applySkin) {
//            SkinManager.getInstance().injectSkin(view);
        }

        ButterKnife.bind(this, view);
        view.setBackgroundDrawable(
                CornerUtils.cornerDrawable(Color.parseColor("#ffffff"), dp2px(5)));
        return view;
    }

    @Override
    public void setUiBeforeShow() {

        //        setText("加载中...");
    }

    public void setText(String text) {
        if (mLoadingText != null) {
            mLoadingText.setText(text);
        }
    }

    //重写系统返回键处理
    @Override
    public void onBackPressed() {
        if (isShowing()) {
            return;
        }
        super.onBackPressed();
    }
}
